//
//  CYRechargeRecordCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/17.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYRechargeRecordCell.h"



@implementation CYRechargeRecordCellObject

@end



@interface CYRechargeRecordCell ()

@property(nonatomic, strong)UILabel *statusLabel;
@property(nonatomic, strong)UILabel *dateLabel;
@property(nonatomic, strong)UILabel *amountLabel;

@property(nonatomic, strong)UIImageView *bottomLine;

@end


@implementation CYRechargeRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.statusLabel = [[UILabel alloc] init];
        self.statusLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.statusLabel];
        
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.font = [UIFont systemFontOfSize:12];
        self.dateLabel.textColor = HEXCOLOR(@"444444");
        [self.contentView addSubview:self.dateLabel];
        
        self.amountLabel = [[UILabel alloc] init];
        self.amountLabel.font = [UIFont systemFontOfSize:18];
        self.amountLabel.textColor = HEXCOLOR(@"444444");
        [self.contentView addSubview:self.amountLabel];
        
        self.bottomLine = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:HEXCOLOR(@"ECECEC") size:CGSizeMake(1, 1)]];
        [self.contentView addSubview:self.bottomLine];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 65;
}

- (BOOL)shouldUpdateCellWithObject:(CYRechargeRecordCellObject *)object
{
    self.statusLabel.textColor = SAFE_NUMBER(object.model.status).integerValue == 4 ? APP_DEFAULT_COLOR_BLUE : APP_DEFAULT_COLOR_RED;
    self.statusLabel.text = SAFE_NUMBER(object.model.status).integerValue == 4 ? @"充值成功" : @"充值处理中";
    
    self.dateLabel.text = [[@((SAFE_NUMBER(object.model.createTime).doubleValue)) cy_date] cy_stringWithFormat:@"yyyy-MM-dd HH:mm"];
    
    self.amountLabel.text = SAFE_NUMBER(object.model.amount).amountString;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.statusLabel sizeToFit];
    self.statusLabel.left = 20;
    self.statusLabel.centerY = 23;
    
    [self.dateLabel sizeToFit];
    self.dateLabel.left = 20;
    self.dateLabel.centerY = 44;
    
    [self.amountLabel sizeToFit];
    self.amountLabel.right = self.contentView.width - 20;
    self.amountLabel.centerY = self.contentView.height / 2;
    
    self.bottomLine.width = self.contentView.width - 20;
    self.bottomLine.height = 1 / SCREEN_SCALE;
    self.bottomLine.bottom = self.contentView.height;
    self.bottomLine.right = self.contentView.width;
}

@end
